﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace weighing
{
    /// <summary>
    /// 火眼臻识 助手类
    /// </summary>
    public class HYZSCameraHelper : ICamera
    {
        /// <summary>
        /// 全局初始化,在所有接口调用之前调用
        /// </summary>
        /// <returns> 0 成功 -1 失败</returns>
        public bool InitSDK()
        {
            return VzClientSDK.VzLPRClient_Setup() == 0;
        }

        /// <summary>
        /// 登陆(打开)一个设备
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port">端口</param>
        /// <param name="userName">用户名</param>
        /// <param name="pwd">密码</param>
        /// <returns>返回设备的操作句柄，当打开失败时，返回0 改成 -1</returns>
        public int Login(string ip, int port, string userName, string pwd)
        {
           int handle = VzClientSDK.VzLPRClient_Open(ip, (ushort)port, userName,pwd);
            if (handle == 0) handle = -1;
            return handle;
        }

        public static int SetIsShowPlateRect(int handle,int isShow)
        {
          return  VzClientSDK.VzLPRClient_SetIsShowPlateRect(handle, isShow);
        }

        /// <summary>
        /// 停止播放
        /// </summary>
        /// <param name="palyHandle">播放的句柄</param>
        /// <returns>0表示成功，-1表示失败</returns>
        public bool StopPreview(int palyHandle)
        {
            int res = VzClientSDK.VzLPRClient_StopRealPlay(palyHandle);
            return res == 0;
        }

        /// <summary>
        /// 播放实时视频
        /// </summary>
        /// <param name="openHandle">登陆成功的句柄</param>
        /// <param name="pictureBoxHandle">窗口的句柄</param>
        /// <returns>播放的句柄，-1表示失败</returns>
        public int Preview(IntPtr pictureBoxHandle,  int openHandle, int channel, out uint errorCode)
        { 
            int playHandle = VzClientSDK.VzLPRClient_StartRealPlay(openHandle, pictureBoxHandle);
            errorCode = (uint)playHandle;
            VzClientSDK.VzLPRClient_SetIsShowPlateRect(openHandle,0);
            return playHandle;
        }




        /// <summary>
        /// 保存正在播放的视频的当前帧的截图到指定路径 ,使用的文件名中的路径需要存在
        /// </summary>
        /// <param name="playHandle">播放的句柄</param>
        /// <param name="path">设带绝对路径和JPG后缀名的文件名字符串</param>
        /// <param name="channel">通道</param>
        /// <param name="quality"> JPEG压缩的质量，取值范围1~100</param>
        /// <returns>0表示成功，-1表示失败</returns>
        public bool CaptureJpeg(int playHandle, string path, int channel, int quality =80)
        {
          int res = VzClientSDK.VzLPRClient_GetSnapShootToJpeg2(playHandle,path,quality);
          return res == 0;
        }

        /// <summary>
        /// 退出（关闭）
        /// </summary>
        /// <param name="loginHandle">登陆成功返回</param>

        public bool LoginOut(int loginHandle)
        {
           return VzClientSDK.VzLPRClient_Close(loginHandle) == 0;
        }
        /// <summary>
        /// 其它品牌使用
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <param name="deviceInfo"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public int Login(string ip, int port, string userName, string pwd, ref CHCNetSDK.NET_DVR_DEVICEINFO_V40 deviceInfo)
        {
            throw new NotImplementedException("非 火眼臻识品牌的实现");
        }
    }
}
